<?php
/**
 * @Notes:【】
 * @Date: 2022-08-06 19:09
 */

namespace App\Service\Ocean;

use App\Constants\OceanEvent;
use App\Dao\Ocean\OceanUserRubbishDao;
use App\Event\Ocean\OceanUserRubbishClear;
use App\Service\BaseService;
use Hyperf\Di\Annotation\Inject;

class OceanUserRubbishService extends BaseService
{

    /**
     * @Inject()
     * @var OceanUserRubbishDao
     */
    protected $oceanUserRubbishDao;

    public function lists(\App\Tool\Collect $params)
    {
        $data = $this->oceanUserRubbishDao->params($params)->with(['OceanRubbish' => function ($query) {
            $query->with(['picture']);
        }])->getList();
        return $data;
    }

    public function clear($id, $userId)
    {
        $oceanUserRubbishDao = $this->oceanUserRubbishDao->params(_Collect(['id' => $id, 'user_id' => $userId]))->firstOrError();
        $oceanUserRubbishDao->delete();
        event()->dispatch(new OceanUserRubbishClear($userId));
        return true;
    }

}